package com.ydkj.a37e_mall.Classes.Acitivity.BaseActivity;

import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.ydkj.a37e_mall.Classes.Model.Response.SortResp;
import com.ydkj.a37e_mall.R;
import com.ydkj.a37e_mall.Resource.Utils.SharedPreferencesUtil;
import com.ydkj.a37e_mall.Resource.View.StatusBarUtil;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/1/9.
 * 分类
 */

public class SortActivity extends BaseActivity {
    private Activity mActivity;
    private SharedPreferencesUtil sharedPreferencesUtil;
    private ListView lv_sort;
    private ImageView img_back;
    private List<SortResp> dataEntityList;
    private SortAdapter sortAdapter;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.sort);
        mActivity = this;
        init();
//        initWindow();
    }

    private void initWindow() {
        StatusBarUtil.setColor(mActivity, getResources().getColor(R.color.A000000), 0);

    }

    private void init() {
        sharedPreferencesUtil = SharedPreferencesUtil.getInstance(mActivity);
        img_back = (ImageView) mActivity.findViewById(R.id.img_back);
        img_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });


        dataEntityList = new ArrayList<SortResp>();
        for (int i = 0; i < 4; i++) {
            SortResp s = new SortResp();
            s.setTag(i);
            dataEntityList.add(s);
        }
        Log.e("ssss", "dataEntityList.size==>" + dataEntityList.size());
        sortAdapter = new SortAdapter(dataEntityList);
        lv_sort = (ListView) mActivity.findViewById(R.id.lv_sort);
        lv_sort.setAdapter(sortAdapter);
    }

    private class SortAdapter extends BaseAdapter {
        private List<SortResp> dataEntityList;

        public SortAdapter(List<SortResp> info) {
            if (info == null) {
                info = new ArrayList<SortResp>();
            }
            dataEntityList = info;
        }

        @Override
        public int getCount() {
            return dataEntityList.size();
        }

        @Override
        public SortResp getItem(int position) {
            return dataEntityList.get(position);
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup viewGroup) {
            ViewHolder vh = null;
            if (convertView == null) {
                convertView = LayoutInflater.from(mActivity).inflate(R.layout.sort_listitem, null);
                vh = new ViewHolder();
                vh.lly_product1 = (LinearLayout) convertView.findViewById(R.id.lly_product1);
                vh.lly_product2 = (LinearLayout) convertView.findViewById(R.id.lly_product2);
                vh.lly_product3 = (LinearLayout) convertView.findViewById(R.id.lly_product3);
                vh.lly_product4 = (LinearLayout) convertView.findViewById(R.id.lly_product4);
                vh.lly_product5 = (LinearLayout) convertView.findViewById(R.id.lly_product5);
                vh.lly_product6 = (LinearLayout) convertView.findViewById(R.id.lly_product6);
                vh.lly_product7 = (LinearLayout) convertView.findViewById(R.id.lly_product7);
                vh.lly_product8 = (LinearLayout) convertView.findViewById(R.id.lly_product8);

                vh.img_product1 = (ImageView) convertView.findViewById(R.id.img_product1);
                vh.img_product2 = (ImageView) convertView.findViewById(R.id.img_product2);
                vh.img_product3 = (ImageView) convertView.findViewById(R.id.img_product3);
                vh.img_product4 = (ImageView) convertView.findViewById(R.id.img_product4);
                vh.img_product5 = (ImageView) convertView.findViewById(R.id.img_product5);
                vh.img_product6 = (ImageView) convertView.findViewById(R.id.img_product6);
                vh.img_product7 = (ImageView) convertView.findViewById(R.id.img_product7);
                vh.img_product8 = (ImageView) convertView.findViewById(R.id.img_product8);

                vh.tv_product1_1 = (TextView) convertView.findViewById(R.id.tv_product1_1);
                vh.tv_product2_1 = (TextView) convertView.findViewById(R.id.tv_product2_1);
                vh.tv_product3_1 = (TextView) convertView.findViewById(R.id.tv_product3_1);
                vh.tv_product4_1 = (TextView) convertView.findViewById(R.id.tv_product4_1);
                vh.tv_product5_1 = (TextView) convertView.findViewById(R.id.tv_product5_1);
                vh.tv_product6_1 = (TextView) convertView.findViewById(R.id.tv_product6_1);
                vh.tv_product7_1 = (TextView) convertView.findViewById(R.id.tv_product7_1);
                vh.tv_product8_1 = (TextView) convertView.findViewById(R.id.tv_product8_1);

                vh.tv_product1_2 = (TextView) convertView.findViewById(R.id.tv_product1_2);
                vh.tv_product2_2 = (TextView) convertView.findViewById(R.id.tv_product2_2);
                vh.tv_product3_2 = (TextView) convertView.findViewById(R.id.tv_product3_2);
                vh.tv_product4_2 = (TextView) convertView.findViewById(R.id.tv_product4_2);
                vh.tv_product5_2 = (TextView) convertView.findViewById(R.id.tv_product5_2);
                vh.tv_product6_2 = (TextView) convertView.findViewById(R.id.tv_product6_2);
                vh.tv_product7_2 = (TextView) convertView.findViewById(R.id.tv_product7_2);
                vh.tv_product8_2 = (TextView) convertView.findViewById(R.id.tv_product8_2);

                vh.tv_title = (TextView) convertView.findViewById(R.id.tv_title);
                vh.rly_product_title = (RelativeLayout) convertView.findViewById(R.id.rly_product_title);
            } else {
                vh = (ViewHolder) convertView.getTag();
            }
            convertView.setTag(vh);
            convertView.setClickable(true);
            return convertView;
        }

        private class ViewHolder {
            private LinearLayout lly_product1, lly_product2, lly_product3, lly_product4, lly_product5, lly_product6, lly_product7, lly_product8;
            private ImageView img_product1, img_product2, img_product3, img_product4, img_product5, img_product6, img_product7, img_product8;
            private TextView tv_product1_1, tv_product2_1, tv_product3_1, tv_product4_1, tv_product5_1, tv_product6_1, tv_product7_1, tv_product8_1;
            private TextView tv_product1_2, tv_product2_2, tv_product3_2, tv_product4_2, tv_product5_2, tv_product6_2, tv_product7_2, tv_product8_2;
            private TextView tv_title;
            private RelativeLayout rly_product_title;
        }
    }


}
